package com.region.spring.cloud.core.listener;

import com.region.common.adapter.json.JSONAdapterFactory;
import com.region.common.adapter.logging.LoggerAdapter;
import com.region.common.adapter.logging.LoggerAdapterFactory;
import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
import org.springframework.context.ApplicationListener;

/**
 * Listen to information about newly registered service instances for subsequent optimization to obtain registry service discovery in real time
 *
 * @author liujieyu
 * @date 2024/10/24 10:45
 * @desciption
 */
public class RegionCloudInstanceListener implements ApplicationListener<InstanceRegisteredEvent> {

    private static final LoggerAdapter loggerAdapter = LoggerAdapterFactory.getLogger(RegionCloudInstanceListener.class);

    @Override
    public void onApplicationEvent(InstanceRegisteredEvent event) {
        if (loggerAdapter.isDebugEnabled()) {
            loggerAdapter.debug("Spring Cloud register instance info:" + JSONAdapterFactory.getAdapter().toJSONString(event.getConfig()));
        }
    }
}
